|
|
|
|
|
|
|
Figure 19.6
The AutoSize property determines whether
the PictureBox control changes to fit the size
of the picture being displayed. Note that
the size of the picture itself does not change. |
|
|
|
|
|
|
|
|
The easiest way to understand how the AutoSize property works is to create a simple test application. First, create a standard project with a file list box and a picture box. Then place the following code in the form: |
|
|
|
|
|
|
|
|
Private Sub Form_Load()
Picture1.AutoSize = True
File1.Path = "C:\Windows"
File1.Pattern = "*.BMP"
End Sub
Private Sub File1_Click()
Picture1.Picture = LoadPicture(File1.Path & "\" & File1.filename)
End Sub |
|
|
|
|
|
|
|
|
As you click a filename in the file list box, notice that the size of the picture box adjusts itself to the size of the loaded picture. Often this type of behavior would be undesirable because the picture box might cover other controls. In that case, you can use an image control or display the picture on a separate form. |
|
|
|
|
|
|
|
|
Using controls is not the only way to add graphics to your application. Visual Basic also provides several methods that you can use to draw on a form or in a PictureBox control. You also can use them with the Printer object to send the output to the printer. If no object is specified with the method, the form that currently has focus receives the output of the methods. |
|
|
|
|
|
|
|
|
You can use the following methods to create many types of graphics images: |
|
|
|
|
|
|
|
|
Line. This method draws a line or a box. |
|
|
|
|
|
|
|
|
Circle. This method draws a circle or oval. |
|
|
|
|
|
|
|
|
PSet. This method places a single point on the target object. |
|
|
|
|
|
|
|
|
Point. This method returns the color of a specific point. |
|
|
|
|
|
|
|
|
PaintPicture. This method draws an image stored in another control onto the target object. |
|
|
|
|
|
|
|
|
Cls. This method clears the output area of the target object. |
|
|
|
|
|
|
|
|
Print. This method places text on the target object. |
|
|
|
|
|